package com.yanqu.road.server.cmd.activity.diggold;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.DigGoldProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.diggold.DigGoldModule;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_DIG_GOLD_OPERATE, desc = "龙脉摸金挖掘 使用道具")
public class DigGoldOperateCmd extends AbstractCommand {

    private int activityId;

    private int operateType;

    private int x;

    private int y;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        DigGoldProto.DigGoldReq req = DigGoldProto.DigGoldReq.parseFrom(packet.getBytes());
        activityId = req.getActivityId();
        operateType = req.getType();
        x = req.getX();
        y = req.getY();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(DigGoldModule.class).digGold(activityId, operateType, x, y);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0){
            DigGoldProto.DigGoldResp.Builder builder = DigGoldProto.DigGoldResp.newBuilder();
            builder.setRet(ret);
            player.sendPacket(ClientProtocol.U_DIG_GOLD_OPERATE, builder);
        }
    }
}
